package com.seedwill.common.model;

import java.util.HashMap;
import java.util.Map;

/**
 * 绑定容器
 * 
 * @author kdyi
 *
 */
public class MapBindingContainer<T> implements java.io.Serializable  {
	/**
	 * Serial Version UID
	 */
	private static final long serialVersionUID = -2321164874081576008L;
	/**
	 * 绑定容器
	 */
	protected Map<String, T> bindings = new HashMap<String, T>();

	/**
	 * 获取绑定
	 * @return
	 */
	public Map<String, T> getBindings() {
		return bindings;
	}

	/**
	 * 设置绑定
	 * @param aBindings
	 */
	public void setBindings(Map<String, T> aBindings) {
		this.bindings = aBindings;
	}

	/**
	 * 注册绑定
	 * @param cmd
	 * @param listener
	 */
	public void registBinding(String cmd, T listener) {
		if (bindings == null) {
			bindings = new HashMap<String, T>();
		}
		bindings.put(cmd, listener);
	}

	/**
	 * 删除绑定
	 * @param cmd
	 */
	public void removeBinding(String cmd) {
		if (bindings != null && bindings.containsKey(cmd)) {
			bindings.remove(cmd);
		}
	}

	/**
	 * 清除绑定
	 */
	public void cleanBinding() {
		if (bindings != null) {
			bindings.clear();
		}
	}

//	public static MapBindingContainer newInstance() {
//		return new MapBindingContainer();
//	}

	/**
	 * 是否包括
	 * @param cmd
	 * @return
	 */
	public boolean containsKey(String cmd) {
		return bindings.containsKey(cmd);
	}

	/**
	 * 获取绑定
	 * @param cmd
	 * @return
	 */
	public T get(String cmd) {
		return bindings.get(cmd);
	}
}
